﻿using AutoMapper;
using B.S.BaseData.Domain;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infratructure.Interfares;
using B.S.BaseData.Write.Api.Application.Command;
using MediatR;

namespace B.S.BaseData.Write.Api.Application.CommandHander
{
    public class UpdateRecodeCommandHander : IRequestHandler<UpdateRecodeCommand, ApiResult<int>>
    {

        private readonly IMapper mapper;
        private readonly IBaseRequsitory<Leave> leaveRequsitory;

        public UpdateRecodeCommandHander(IMapper mapper, IBaseRequsitory<Leave> leaveRequsitory)
        {
            this.mapper = mapper;
            this.leaveRequsitory = leaveRequsitory;
        }

        /// <summary>
        /// 申请人修改提交申请
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResult<int>> Handle(UpdateRecodeCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();

            #region   修改申请表
            var entity = mapper.Map<Leave>(request);
            await leaveRequsitory.UpdateAsync(entity);
            #endregion

            result.Code = ApiEnum.修改成功;
            result.Msg = ApiEnum.修改成功.ToString();

            return await Task.FromResult(result);

        }
    }
}
